$(function () {
	// body...
    localStorage.indexName = titleIndex;

    $.ajax({
        url: 'http://47.89.20.150/czlycms/index.php?m=Web&a=newsroom',
        type: 'GET',
        dataType: 'JSONP'
    })
    .done(function(data) {
        console.log("success");
        console.log(data);
        announcementsFun(data.announcements);
        feature_newsFun(data.feature_news);
        photosFun(data.photos);
        
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });
})





// announcements
function announcementsFun(data){
    var dari = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
    var ANNList = $('#ANNList');
    var html = '';
    var moer = '<li class="clearfloat"><a href="pageList.html?cate_id=18" class="bot">MORE</a> </li>';

    for (var i = 0; i < data.length; i++) {
        var issueDate = data[i].issueDate
        var nian = (issueDate.split("-"))[0];
        var yue = (issueDate.split("-"))[1];
        var ri = (issueDate.split("-"))[2];

        var cn = '<li class="clearfloat">'+
        ' <div class="timeCom">'+dari[(yue-1)] +' '+ri+', '+nian+'</div>'+
        '<div class="RigCon">'+
        '<a href="article.html?article_id='+data[i].article_id+'">'+
        '<p>'+data[i].title+'</p>'+
        '<span>PRESS RELEASE</span>'+
        '</a>'+
        '</div>'+
        '</li>';
        html+=cn;
    }
    ANNList.html(html +moer);
}
// announcements end

// feature_news
function feature_newsFun(data){
    var dari = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
    
   var FeaturelsCn = $('#FeaturelsCn');
   var html = '';

   for (var i = 0; i < data.length; i++) {
      
    var cn = '<li>'+
    '<a href="article.html?article_id='+data[i].article_id+'" class="clearfloat">'+
    '<div class="imgc"><img src="'+data[i].image_url+'"></div>'+
    '<div class="Wr">'+
    ' <h3>'+data[i].title+'</h3><p>'+data[i].seo_description+'</p><div class="time">'+dari[((data[i].issueDate.split("-"))[1])-1]+' '+(data[i].issueDate.split("-"))[2]+', '+(data[i].issueDate.split("-"))[0]+'</div>'+
    '</div>'+
    '</a>'+
    '</li>';
    html+=cn;
}
FeaturelsCn.html(html);
}
// feature_news end



// photos
function photosFun(data){
   var photosCon = $('#photosCon');
   var html = '';

   for (var i = 0; i < data.length; i++) {
      
    var cn = '<li class="'+IFOne(i)+'">'+
    '<a href="javascript:void(0);">'+
    '<img class="photo" data-in="'+(i+1)+'" src="'+data[i].image_url+'">'+
    '<div class="men">'+
    '<div class="title">'+data[i].title+'</div>'+
    '<p>'+data[i].describe+'</p>'+
    '<span class="iconCn"><i class="iconfont">&#xe601;</i></span>'+
    '</div>'+
    '</a>'+
    '</li>';
    html+=cn;
}

function IFOne(i){
    if (i == 0) {
        return 'one';
    }else{
        return 'two';
    }
}
photosCon.html(html);
PhotosFrameFun();



}
// photos end


//PHOTOS 弹出 相框 
function PhotosFrameFun(){
    var Con = $('#PhotosFrame');
    var Exit = $('#ExitPhotosFrame');
    var next = Con.find('.nextFrame');
    var prev = Con.find('.prevFrame');
    var imgCon = Con.find('.imgCon');

    var NCon = $('#photosCon');
    var img = NCon.find('img.photo');

    console.log(img.length);
    var Dataimg = [];
    var index = 0;

    for (var i = 0; i < img.length; i++) {

        Dataimg[i] = img.eq(i).attr('src');
    }

                // console.log(Dataimg);
                // console.log(Dataimg.length);

                NCon.on('click','span.iconCn',function(){
                    index =  parseInt($(this).parents('a').find('img').attr('data-in') -1);
                    console.log(index);
                    imgCon.find('img').attr('src',Dataimg[index]);




                    Con.show();
                    setTimeout(function(){
                        imgCon.addClass('active')
                    },1)

                })
                next.click(function(){
                    index--;
                    if (index < 0) {
                        index = (Dataimg.length - 1);
                    }
                    console.log(index)
                    imgCon.find('img').attr('src',Dataimg[index]);
                })
                prev.click(function(){
                    index++;
                    if (index >(Dataimg.length - 1)) {
                        index = 0;
                    }
                    console.log(index)

                    imgCon.find('img').attr('src',Dataimg[index]);
                })

                Exit.click(function(){
                    imgCon.removeClass('active')
                    setTimeout(function(){
                        Con.hide();
                    },300)
                })
            }
            

//PHOTOS 弹出 相框 end